//*****************************************************************************
//
//! \file MPL115A1.h
//! \brief Driver for MPL115A1 Sensor.
//! \version 1.0.0.0
//! \date 12/31/2012
//! \author Nemon
//! \copy
//!
//! Copyright (c)  2011, CooCoX
//! All rights reserved.
//!
//! Redistribution and use in source and binary forms, with or without
//! modification, are permitted provided that the following conditions
//! are met:
//!
//!     * Redistributions of source code must retain the above copyright
//! notice, this list of conditions and the following disclaimer.
//!     * Redistributions in binary form must reproduce the above copyright
//! notice, this list of conditions and the following disclaimer in the
//! documentation and/or other materials provided with the distribution.
//!     * Neither the name of the <ORGANIZATION> nor the names of its
//! contributors may be used to endorse or promote products derived
//! from this software without specific prior written permission.
//!
//! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
//! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
//! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
//! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
//! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
//! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
//! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
//! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
//! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
//! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
//! THE POSSIBILITY OF SUCH DAMAGE.
//
//*****************************************************************************

#ifndef __MPL115A1_H__
#define __MPL115A1_H__


//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif

//*****************************************************************************
//
//! \addtogroup CoX_Shield_Lib
//! @{
//
//*****************************************************************************

//*****************************************************************************
//
//! \addtogroup Sensor
//! @{
//
//*****************************************************************************

//*****************************************************************************
//
//! \addtogroup Pressure_Sensor
//! @{
//
//*****************************************************************************

//*****************************************************************************
//
//! \addtogroup MPL115A1
//! @{
//
//*****************************************************************************

//*****************************************************************************
//
//! \addtogroup MPL115A1_Configs  MPL115A1 Driver config
//! \brief pins of MPL115A1 config.(
//!  NOTE: 1. CLOCK MUST less than 8MHz
//!        2. If you do not use SHDN, comment "MPL115A1_SPI_SHDN".
//!        3. If you are useing cookie, SPI_CHOICE only can be 0 or 1.
//! \verbatim
//! +-------------+----------------+--------------------------------------+
//! |SPI_CHOICE   |SPI_BASE        |Pin Define                            |
//! |-------------|----------------|--------------------------------------|
//! |0            |SPI0            |CLK:PB7,MOSI:PB5,MISO:PB6,CS:PB4      |
//! |-------------|----------------|--------------------------------------|
//! |1            |SPI1            |CLK:PA7,MOSI:PA5,MISO:PA6,CS:PA4      |
//! |-------------|----------------|--------------------------------------|
//! \endverbatim
//
//! @{
//
//*****************************************************************************
#define MPL115A1_SPI_CLOCK   (8000000)
#define MPL115A1_SPI_1ms     ((MPL115A1_SPI_CLOCK)/1000)

#define MPL115A1_SPI_SHDN    sD2

#define MPL115A1_SPI_CHOICE  1

#if (MPL115A1_SPI_CHOICE==0)

#define MPL115A1_SPI_BASE    xSPI0_BASE
#define MPL115A1_SPI_CLK_    SPI0CLK
#define MPL115A1_SPI_MOSI_   SPI0MOSI
#define MPL115A1_SPI_MISO_   SPI0MISO
#define MPL115A1_SPI_CS_     SPI0CS
#define MPL115A1_SYSCTL_PERIPH_SPI \
                             xSYSCTL_PERIPH_SPI0
#define MPL115A1_SPI_CLK     PB7
#define MPL115A1_SPI_MOSI    PB5
#define MPL115A1_SPI_MISO    PB6
#define MPL115A1_SPI_CS      PB4

#elif (MPL115A1_SPI_CHOICE==1)

#define MPL115A1_SPI_BASE    xSPI1_BASE
#define MPL115A1_SPI_CLK_    SPI1CLK
#define MPL115A1_SPI_MOSI_   SPI1MOSI
#define MPL115A1_SPI_MISO_   SPI1MISO
#define MPL115A1_SPI_CS_     SPI1CS
#define MPL115A1_SYSCTL_PERIPH_SPI \
                             xSYSCTL_PERIPH_SPI1
#define MPL115A1_SPI_CLK     PA7
#define MPL115A1_SPI_MOSI    PA5
#define MPL115A1_SPI_MISO    PA6
#define MPL115A1_SPI_CS      PA4

#endif

//*****************************************************************************
//
//! @}
//
//*****************************************************************************

//*****************************************************************************
//
//! \addtogroup MPL115A1_Enable_Config MPL115A2 Enable Config
//! \brief only useed by driver, DON'T chang them.
//! @{
//
//*****************************************************************************
#define MPL115A1_SPI_ENABLE  1
#define MPL115A1_SPI_DISABLE 0


//*****************************************************************************
//
//! @}
//
//*****************************************************************************

//*****************************************************************************
//
//! \addtogroup MPL115A1_Exported_APIs  MPL115A1 Driver APIs
//! \brief API Refrence of MPL115A1 Driver.
//! @{
//
//*****************************************************************************

//*****************************************************************************
//
//! \brief make sensor init.
//!
//! make sensor init.
//!
//! \return None
//
//*****************************************************************************
extern void MPL115A1Init(void);

//*****************************************************************************
//
//! \brief get current pressure value.
//!
//! get current pressure value.
//!
//! \return int[16,4] the pressure value
//
//*****************************************************************************
extern signed short MPL115A1GetPressure();

//*****************************************************************************
//
//! \brief translate int[16,4] pressure value to float.
//!
//! \param uiValue is pressure value of int[16,4].
//!
//! translate int[16,4] pressure value to float.
//!
//! \return float pressure value
//
//*****************************************************************************
#define MPL115A1TranslateValue(uiValue) \
                                ((float)(uiValue))/(1<<4)

//*****************************************************************************
//
//! @}
//
//*****************************************************************************

//*****************************************************************************
//
//! @}
//
//*****************************************************************************

//*****************************************************************************
//
//! @}
//
//*****************************************************************************

//*****************************************************************************
//
//! @}
//
//*****************************************************************************

//*****************************************************************************
//
//! @}
//
//*****************************************************************************

//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif

#endif //__MPL115A1_H__
